{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=1170
  Verdict: Accepted
}
uses 
	SysUtils, Math;
 
var  	
	i,j,n,l,r:longint;
	a:array[0..100010] of longint;
 
begin
reset(input,'input.txt');
rewrite(output,'output.txt');
read(n);
for i:=1 to n do 
	read(a[i]);
for i:=n downto 1 do begin
	j:=i;
	while true do begin
		l:=j shl 1;
		r:=l+1;
		if (l<=n) and (r<=n) then begin
			if (a[l]>=a[r]) and (a[j]<a[l]) then begin
				a[l]:=a[l] xor a[j];
				a[j]:=a[j] xor a[l];
				a[l]:=a[l] xor a[j];
				j:=l;
			end else 
			if (a[r]>=a[l]) and (a[j]<a[r]) then begin
				a[r]:=a[r] xor a[j];
				a[j]:=a[j] xor a[r];
				a[r]:=a[r] xor a[j];
				j:=r;
			end else break;
		end else begin
			if (l<=n) and (r>n) and (a[j]<a[l]) then begin
				a[l]:=a[l] xor a[j];
				a[j]:=a[j] xor a[l];
				a[l]:=a[l] xor a[j];
				j:=l;				
			end else break;
		end;	
	end;
end;
for i:=1 to n do
	write(a[i],' ');
end.